//登录状态检查
function loginCheck() {
    var local = getData('login');

    // console.log(local);
    if (local.length != 0) {
        var id = local.user;
        $(".login-check span").html(`
        <a href="user.html">用户:${id}</a>
        <a href="#"  id="login-clear">退出</a>
        `);
    }
    else {
        $(".login-check span").html(`
        <a href="login.html">登录</a>
        <a href="register.html">注册</a>
                
        `);
    }

}
//调用
loginCheck();

//退出登录状态
$('#login-clear').click(function () {
    if (confirm('确认要退出登录么？') == true) {
        localStorage.removeItem('login');
        loginCheck();
    }


})
//获取本地数据
function getData(name) {
    var local = localStorage.getItem(name);
    if (local != null) {
        return JSON.parse(local);
    } else {
        return [];
    }
}

